package hot.huisu;

import java.util.ArrayList;
import java.util.List;

public class A46 {
    public static void main(String[] args) {
        A46 a=new A46();
        a.permute(new int[]{1,2,3});
        for (List<Integer> list : a.list) {
            for (Integer i : list) {
                System.out.print(i+" ");
            }
            System.out.println();
        }
    }
    List<List<Integer>> list=new ArrayList<>();
    List<Integer> path=new ArrayList<>();
    int[] vis;
    public List<List<Integer>> permute(int[] nums) {
int len=nums.length;
        vis=new int[len];
        dfs(0,len,nums);
        return list;
    }
    void dfs(int t,int u,int[] nums){
        //头部判断
        if(t==u){
            list.add(new ArrayList<>(path));
            return;
        }
        for(int i=0;i<u;i++){
            if(vis[i]==0){
                vis[i]=1;
                path.add(nums[i]);
                dfs(t+1,u,nums);
                vis[i]=0;
                path.remove(t);
            }
        }
    }
}
